package com.glory.nicleanrpt

import com.ivan.utils.PathUtil
import com.tsqc.system.util.table.TranposUtils

/**
 * @Program: njcleanrpt
 * @Description: 清洗次数
 * @Author: ivan
 */
class CleanCountsController {

    def dynamicQueryService
    def commonSQLService

    def cleanCounts() {
        request.setCharacterEncoding("UTF-8")
        response.setContentType("text/html;charset=UTF-8")
        def report_011 = []
        def tableHeadList = []
        def totalCount = 0
        // 客户
        def customNameList = commonSQLService.customNameList(params)
        // 装置
//        params.SYS_QUERY_NAME = 'deviceNameByCleanCountList'
//        def deviceNameList = dynamicQueryService.queryForList(params)
        def sysQueryName
        def sysQueryPath = PathUtil.getPath(this, request)
        if ('Excel'.equals(params.EXPORT_CONTENT_NAME)) {
            params.SYS_QUERY_NAME = 'cleanCountsList'
            report_011 = dynamicQueryService.queryForList(params)
            report_011 = TranposUtils.colToRow('清洗时间', 'CREATED', report_011)
            if (report_011.size() > 0) {
                tableHeadList = report_011[0].keySet()
            }
            sysQueryName = params.SYS_QUERY_NAME
            totalCount = report_011.size()
        }
        [
                customName    : params.customName ?: '',
                deviceName    : params.deviceName ?: '',
                partName      : params.partName ?: '',
                markNum       : params.markNum ?: '',
                customNameList: customNameList,
//                deviceNameList: deviceNameList,
                report_011    : report_011,
                totalCount    : totalCount,
                tableHeadList : tableHeadList,
                SYS_QUERY_PATH: sysQueryPath,
                SYS_QUERY_NAME: sysQueryName
        ]
    }

    def exportExcel() {
        params.startno = 1
        params.endno = 99999999999999999
        params.SYS_QUERY_NAME = 'cleanCountsList'
        def cleanCountsList = dynamicQueryService.queryForList(params)
        cleanCountsList = TranposUtils.colToRow('清洗时间', 'CREATED', cleanCountsList)
        def tableHeadList = []
        if (cleanCountsList.size() > 0) {
            tableHeadList = cleanCountsList[0].keySet()
        }
        String filename = new String("cleanCount.xls".getBytes("UTF-8"), "UTF-8");
        response.setContentType('application/vnd.ms-excel;charset=UTF-8')
        response.setHeader('Content-disposition', "attachment;filename=${filename};charset=UTF-8")
        response.setCharacterEncoding("UTF-8");
        render(template: "export${params.EXPORT_CONTENT_NAME}", model: [dataList: cleanCountsList, tableHeadList: tableHeadList, startno: params.startno, endno: params.endno])
    }
}